#include "BinExBench.h"



void BinExBench::executeFFT() { executeFFT(false); }

void BinExBench::executeFFT(bool onlyComm) {



	//transpose
	//MPI_Alltoall(localData,2,MPI_DOUBLE,localBuff,2,MPI_DOUBLE,MPI_COMM_WORLD);

	for (int mSize=1; mSize <= MAXN; mSize*=2) {

		int trial;
		double startTime;
		double endTime;

		MPI_Barrier(MPI_COMM_WORLD);
		
		startTime = MPI_Wtime();
		for (trial=0; trial < 10; trial++) {


			int lgp = log2(numNodes);

			for (int s=0; s < lgp; s++) {
	
				int partRank = rank ^ (1 << (lgp-s-1));
				MPI_Sendrecv(sendBuff,mSize*numNodes,MPI_DOUBLE,partRank,s,
				     	recBuff,mSize*numNodes,MPI_DOUBLE,partRank,s,
				     	MPI_COMM_WORLD,&(comm->status));
			}



			//MPI_Alltoall(sendBuff,mSize,MPI_DOUBLE,recBuff,mSize,MPI_DOUBLE,MPI_COMM_WORLD);
		
			//swap send and rec pointers
			double *tmp = sendBuff;
			sendBuff = recBuff;
			recBuff = tmp;
		}
		
		endTime = MPI_Wtime();
		if (rank == 0) {
			printf("B;%d;%d;%lf\n",numNodes,mSize,(endTime-startTime)/trial);
		}		

	}
	
}

